package com.example.gustavo.hello.activity;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.Animation;
import android.widget.ImageView;

import com.example.gustavo.hello.R;
import com.example.gustavo.hello.animation.Rotate3dAnimation;

public class MaterialDesighActivity extends AppCompatActivity {

    private ImageView imageView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_material_desigh);


        imageView = (ImageView) findViewById(R.id.iv);


    }

    public void change(View view){

        Rotate3dAnimation rotate3dAnimation = new Rotate3dAnimation(0f, 180f, imageView.getWidth()/2, imageView.getHeight()/2, 0, false);
        rotate3dAnimation.setDuration(500);
//        rotate3dAnimation.setFillAfter(true);
        rotate3dAnimation.setInterpolator(new AccelerateInterpolator());
        rotate3dAnimation.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {

            }

            @Override
            public void onAnimationEnd(Animation animation) {

                if(imageView.getContentDescription().equals("0")){

                    imageView.setContentDescription("1");
                    imageView.setImageResource(R.drawable.bg);
                }else{
                    imageView.setContentDescription("0");
                    imageView.setImageResource(R.drawable.ic_launcher);
                }
            }

            @Override
            public void onAnimationRepeat(Animation animation) {

            }
        });

        imageView.startAnimation(rotate3dAnimation);

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_material_desigh, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
}
